<?php
require_once 'adminmenu.php';
?>
<div class="well">
    <h4>Side menu:</h4>
<?php
$content = new Models_Menu();
$menuHeader = $content->getMenu(' ');
$articleList = new Models_Articles();
echo '<table class="table table-striped">';
echo '<thead>';
echo '<tr>';
echo '<th>#</th><th>name</th><th>created/modified</th><th>actions</th><th>You owner?</th>';
echo '</tr>';
echo '</thead><tbody>';
foreach ($menuHeader as $head)  //---------HEADER-LIST--------
{
    echo '<tr class=""><td></td><td><u>'
            . $head['name'] .
            '</u></td><td>--</td><td><a class="btn btn-primary btn-mini" href="/'
            . $content->path . 'menu/edit/' . $head['id'] . '"><i class="icon-pencil icon-white"></i></a>
            <a class="btn btn-danger btn-mini" href="#"><i class="icon-remove icon-white"></i></a></td><td>?</td></tr>';
    $subMenu = $content->getSubMenu($head['id'], ' ');
    echo '<tbody class="menu-head">';
    foreach ($subMenu as $sub) //-----------ARTICLES-~LIST------
    {
        echo '<tr class=""><td>'
                . $sub[$content->lang . '_article_id'] 
                . '</td><td>|' 
                . $sub['name'] 
                . '</td><td>-</td><td><a class="btn btn-primary btn-mini" href="/' 
                . $content->path 
                . 'articles/edit/' . $sub[$content->lang . '_article_id'] . '"><i class="icon-pencil icon-white"></i></a>
                <a class="btn btn-danger btn-mini" href="#"><i class="icon-remove icon-white"></i></a> 
                <a href="/' . $content->path . 'articles/addtagto/' . $sub[$content->lang . '_article_id'] . '" class="btn btn-mini btn-info"><i class="icon-tag icon-white"></i></a>
                <a href="/' . $content->path . 'articles/permission/' . $sub[$content->lang . '_article_id'] . '" class="btn btn-info btn-mini"><i class="icon-check icon-white"></i></a></td><td>?</td></tr>';
        $articles = $articleList->getAllSubArticles($sub[$content->lang . '_article_id']);
        foreach ($articles as $article) //------------SUB-ARTICLES-LIST----
        {
            echo '<tr><td>' 
                    . $article['id'] 
                    . '</td><td>->' 
                    . $article['title'] 
                    . '</td><td>' 
                    . $article['modified'] 
                    . '</td><td><a class="btn btn-primary btn-mini" href="/' 
                    . $content->path . 'articles/editsub/' 
                    . $article['id'] 
                    . '"><i class="icon-pencil icon-white"></i></a>
                    <a class="btn btn-danger btn-mini" href="#"><i class="icon-remove icon-white"></i></a>
                    <a href="/' . $content->path . 'articles/subpermission/' . $sub[$content->lang . '_article_id'] . '" class="btn btn-info btn-mini"><i class="icon-check icon-white"></i></a></td><td>?</td></tr>';
        }
    }
    echo '</tbody>';
}
echo '</tbody></table>';
?>
</div>